﻿package net.wangit.dev.wizard.unit;

import net.wangit.dev.wizard.WizardUtil;
import net.wangit.framework.config.WizardSettings;
import net.wangit.jdbc.ColumnRow;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.Table;
import net.wangit.util.Checker;

public class AFormUnit {

	public AFormUnit() {
	}

	public static final void create(DB db, String domain, String groupId,
			String unitId, String unitName, String tableName, int accessible,
			String parentUnitId) throws Exception {
		Table table = new Table("dev", "UNIT");
		ColumnRow cRow = table.addInsertRow();
		cRow.set("uid", unitId);
		cRow.set("gid", groupId);
		cRow.set("c", 1);
		cRow.set("ti", unitName);
		cRow.set("co", WizardSettings.instance().getFormColumn());
		cRow.set("cc", WizardSettings.instance().getFormColsConfig());
		cRow.set("t", tableName);
		cRow.set("dm", 1);
		cRow
				.set("de", WizardUtil.getFormUnitSql(db, domain, tableName,
						unitId));
		if (!Checker.isEmpty(parentUnitId))
			cRow.set("pid", parentUnitId);
		cRow.set("ub", WizardSettings.instance().getFormShowUnitBorder());
		cRow.set("tb", WizardSettings.instance().getFormShowTitleBorder());
		cRow.set("gb", WizardSettings.instance().getFormShowGridBorder());
		cRow.set("cb", WizardSettings.instance().getFormShowCellBorder());
		cRow.set("pp", accessible);
		cRow.set("au", accessible);
		cRow.set("ms", "1");
		cRow.set("me", "1");
		cRow.set("ma", "1");
		cRow.set("l", "0");
		cRow.set("y", "0");
		db.save(table);
	}
}
